🧮 Winning Factors Challenge

Overview

The "Winning Factors" challenge, created by syyntax, tests your ability to solve math equations in real-time using Python socket programming. The challenge involves calculating factorials and submitting the results to a remote server.

Challenge Details

Provided Information

No files were provided for this challenge. You need to connect to the remote server and solve the equations using the provided socket programming code.

Solution Process

Socket Programming Explanation

The challenge requires connecting to the remote server via socket programming. The server sends a mathematic equation, specifically the factorial of a number, and the player needs to calculate the answer and send it back within 3 seconds.

Provided Python Code

import socket
import re
from math import factorial

def calculate_factorial(n):
    try:
        return factorial(n)
    except ValueError as e:
        print(f"Error calculating factorial: {e}")
        return None

def connect_and_solve():
    host = "147.182.245.126"
    port = 33001

    s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    s.settimeout(5)  
    s.connect((host, port))

    try:
        while True:
            data = s.recv(1024).decode().strip()
            if not data:
                continue

            print(f"Received: '{data}'")

            if "flag{" in data:
                print("Found flag:", data)
                break

            number_match = re.search(r'factorial of (\d+)\.?', data)
            if number_match:
                number = int(number_match.group(1))
                answer = calculate_factorial(number)

                if answer is not None:
                    response = str(answer)
                    print(f"Sending answer: {response}")
                    s.send(response.encode())

                    feedback = s.recv(1024).decode().strip()
                    print(f"Server response: '{feedback}'")

    except socket.timeout:
        print("Socket timeout occurred")
    except Exception as e:
        print(f"Error occurred: {e}")
    finally:
        s.close()

if __name__ == "__main__":
    connect_and_solve()

Decoded Flag

After submitting the correct answers to the server, the flag received is: flag{1ntr0_f4ct0r14l_5t3p}